package com.boolib.shopweb.web;

import com.boolib.bo.RedisCartBo;
import com.boolib.commons.aop.annotation.IsLogin;
import com.boolib.commons.entity.ServerResponse;
import com.boolib.commons.util.HttpSessionUtil;
import com.boolib.pojo.ShopUser;
import com.boolib.service.ICartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private ICartService iCartService;

    @IsLogin
    @RequestMapping("/add")
    public ServerResponse addSku( RedisCartBo redisCartBo ,HttpSession httpSession){

        ShopUser shopUser = HttpSessionUtil.getShopUser(httpSession);

       return iCartService.add(shopUser.getId(),redisCartBo);
    }




    @IsLogin
    @RequestMapping("/sub")
    public ServerResponse subSku( RedisCartBo redisCartBo ,HttpSession httpSession){

        ShopUser shopUser = HttpSessionUtil.getShopUser(httpSession);

        return iCartService.sub(shopUser.getId(),redisCartBo);
    }



    @IsLogin
    @RequestMapping("/removeOne")
    public ServerResponse removeOneSku( Integer skuId ,HttpSession httpSession){

        ShopUser shopUser = HttpSessionUtil.getShopUser(httpSession);

        return iCartService.removeOne(shopUser.getId(),skuId);
    }


    @IsLogin
    @RequestMapping("/removeAll")
    public ServerResponse removeAllSku( Integer skuId ,HttpSession httpSession){

        ShopUser shopUser = HttpSessionUtil.getShopUser(httpSession);

        return iCartService.removeAll(shopUser.getId());
    }




}
